/*
 *
 *      Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: lengleng (wangiegie@gmail.com)
 *
 */

package com.pig4cloud.pigx.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.dto.ReservoirStabilityDto;
import com.pig4cloud.pigx.admin.api.entity.OverallReservoirStability;
import com.pig4cloud.pigx.admin.api.vo.ReservoirStabilityAnalysisVo;
import com.pig4cloud.pigx.admin.api.vo.ReservoirStabilityVo;
import com.pig4cloud.pigx.admin.converter.OverallReservoirStabilityConverter;
import com.pig4cloud.pigx.admin.mapper.OverallReservoirStabilityMapper;
import com.pig4cloud.pigx.admin.service.OverallReservoirStabilityService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 四全库岸稳定性 服务实现类
 * </p>
 *
 * @author lengleng
 * @since 2018-01-20
 */
@Service
@AllArgsConstructor
public class OverallReservoirStabilityServiceImpl extends ServiceImpl<OverallReservoirStabilityMapper, OverallReservoirStability> implements OverallReservoirStabilityService {


    private final OverallReservoirStabilityMapper mapper;

    private final OverallReservoirStabilityConverter converter;


    /**
     * @param res
     * @return ReservoirStabilityVo
     * @author lfx
     * @date 2024/8/10 16:20
     * @Desc 查询款稳定性占比分析
     **/
    @Override
    public List<ReservoirStabilityAnalysisVo> queryAnalysis(ReservoirStabilityDto res) {
        List<ReservoirStabilityAnalysisVo> stabilityVoList = mapper.selectRatioAnalysis();
        return stabilityVoList;
    }

    /**
     * @param res
     * @return List<ReservoirStabilityVo>
     * @author lfx
     * @date 2024/8/10 16:31
     * @Desc 根据类型查询库案稳定性列表
     **/
    @Override
    public List<ReservoirStabilityVo> queryListByType(ReservoirStabilityDto res) {
        List<OverallReservoirStability> stabilityList = mapper.selectList(Wrappers.lambdaQuery(OverallReservoirStability.class)
                .eq(StringUtils.isNotEmpty(res.getStableType()), OverallReservoirStability::getStableType, res.getStableType()));
        if(CollUtil.isNotEmpty(stabilityList)){
            return converter.doListToVoList(stabilityList);
        }
        return Collections.emptyList();
    }

    /**
     *
     * @param res
     * @return OverallReservoirStability
     * @author lfx
     * @date 2024/8/10 16:46
     * @Desc 根据id查询库案稳定性详情
     **/
    @Override
    public OverallReservoirStability queryById(ReservoirStabilityDto res) {
        Assert.notNull(res.getStabilityId(), "id不能为空");
        OverallReservoirStability overallReservoirStability = mapper.selectOne(Wrappers.lambdaQuery(OverallReservoirStability.class)
                .eq(OverallReservoirStability::getId, res.getStabilityId()));
        return overallReservoirStability;
    }
}
